//
//  ANProductInfoViewController.m
//  Ants
//
//  Created by ZHM on 16/3/31.
//  Copyright © 2016年 ZHM. All rights reserved.
//

#import "ANProductInfoViewController.h"



@interface ANProductInfoViewController ()

@property (nonatomic, strong) NSDictionary *productInfo;

@end

@implementation ANProductInfoViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"商品规格";
    
    [self configureTableView];

    
    if (self.product.info.length > 0) {
        NSError *jsonError;
        NSData *objectData = [self.product.info dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:objectData options:NSJSONReadingMutableContainers error:&jsonError];
        if (!jsonError) {
            self.productInfo = json;
        }
    }
}


#pragma mark -UITableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"BasicCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }
    NSString *key = self.productInfo.allKeys[indexPath.row];
    NSString *value = self.productInfo[key];
    cell.textLabel.text = key;
    cell.detailTextLabel.text = value;
    cell.detailTextLabel.numberOfLines = 0;
    
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSLog(@"%ld",(unsigned long)[self.productInfo.allKeys count]);
    return [self.productInfo.allKeys count];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)configureTableView {
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.backgroundColor = UIColorFromRGB(0xeeeeee);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
